package com.iversonx.adapter.example_1.service.v2;

import com.iversonx.adapter.example_1.remote.db.LogDbOperateApi;
import com.iversonx.adapter.example_1.remote.file.LogFileOperateApi;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 *
 **/
@Configuration
public class LogAdapterConfig {
    @Autowired
    private LogDbOperateApi dbOperateApi;
    @Autowired
    private LogFileOperateApi fileOperateApi;
    
    @Bean
    @ConditionalOnProperty(name = "logType", havingValue = "1")
    @ConditionalOnMissingBean
    public LogAdapter logDbAdapter() {
        return new LogDbAdapter(dbOperateApi);
    }
    
    @Bean
    @ConditionalOnProperty(name = "logType", havingValue = "2")
    public LogAdapter logFileAdapter() {
        return new LogFileAdapter(fileOperateApi);
    }
}
